#!/bin/bash
#
# Patch osgt produced with osgexporter to remove unused bits.
# The result is sent to stdout.
#
FILE=$1
if [ -z $FILE ]; then
    echo "$0 OSGT_FILE"
    exit
fi
#sed -n '1h;1!H;${;g;s/StateSet TRUE.*Children 3/StateSet TRUE {\n    osg::StateSet {\n      UniqueID 367\n      AttributeList 1 {\n        osg::Material {\n          UniqueID 369\n          Diffuse TRUE Front 1 1 1 1 Back 1 1 1 1\n        }\n        Value OFF\n      }\n    }\n  }\n  Children 1/g;p;}' $FILE | sed -n '1h;1!H;${;g;s/StateSet TRUE.*PrimitiveSetList/PrimitiveSetList/g;p;}' | sed -n '1h;1!H;${;g;s/Lamp.*\}//g;p;}' | head -n -3
sed -n '1h;1!H;${;g;s/StateSet TRUE.*Children 3/Children Top/g;p;}' $FILE | sed -n '1h;1!H;${;g;s/StateSet TRUE.*PrimitiveSetList/PrimitiveSetList/g;p;}' | sed -n '1h;1!H;${;g;s/Lamp.*\}//g;p;}' | sed -n '1h;1!H;${;g;s/Children Top/StateSet TRUE {\n    osg::StateSet {\n      UniqueID 367\n      AttributeList 1 {\n        osg::Material {\n          UniqueID 369\n          Diffuse TRUE Front 1 1 1 1 Back 1 1 1 1\n        }\n        Value OFF\n      }\n    }\n  }\n  Children 1/g;p;}' | head -n -3
echo -e "  }\n}"
